<template>
  <el-input v-model="textValue" @blur="handleBlur" @enter="handleBlur" />
</template>

<script setup lang="ts">
//import { ProductApi, ProductVO } from '@/api/erp/product/product'
import {StockApi} from '@/api/erp/stock/stock'
const props = defineProps({
  row: {
    type: Object,
    default: () => ({})
  },
  keyValue: {
    type: String,
    default: '',
    required: true
  }
})
const emit = defineEmits(['success'])
const textValue = ref('')

const message = useMessage() // 消息弹窗
const handleBlur = async () => {
  await StockApi.updateProduct({...props.row, [props.keyValue]: Number(textValue.value) })
  message.success('更新成功')
  emit('success')
}

watch(
  () => [props.row, props.keyValue], // props.row,
  () => {
    textValue.value = props.row[props.keyValue]
  },
  { immediate: true }
)

</script>